from django.db import models


# Create your models here.
class Coupon(models.Model):
    '''优惠券'''
    name = models.CharField(max_length=20, verbose_name="优惠券名称")
    price = models.IntegerField(default=0, verbose_name="优惠券价格")
    conditions = models.CharField(max_length=20, verbose_name="使用条件")
    starttime = models.DateTimeField(verbose_name="开始时间",null=True, blank=True)
    endtime = models.DateTimeField(verbose_name="结束时间", blank=True, null=True)
    validity = models.IntegerField(default=0, verbose_name="有效期", blank=True, null=True)
class User(models.Model):
    '''用户'''
    name = models.CharField(max_length=20, verbose_name="姓名")
    phone = models.CharField(max_length=11, verbose_name="手机号")
    img = models.ImageField(upload_to="img", verbose_name="头像", blank=True, null=True,default="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg")
    score = models.IntegerField(default=0, verbose_name="积分")
    balance = models.IntegerField(default=0, verbose_name="余额")

class Outlet(models.Model):
    '''网点'''
    name = models.CharField(max_length=20, verbose_name="姓名")
    address = models.CharField(max_length=100, verbose_name="地址")
    status = models.BooleanField(default=True, verbose_name="营业状态")


class Equipment(models.Model):
    '''设备'''
    name = models.CharField(max_length=20, verbose_name="设备名称")
    eid = models.CharField(max_length=20, verbose_name="设备编号", unique=True)
    type = models.CharField(max_length=20, verbose_name="设备类型")
    floor = models.CharField(max_length=20, verbose_name="楼层")
    status = models.BooleanField(default=True, verbose_name="设备状态")
    oid = models.ForeignKey(Outlet, on_delete=models.CASCADE, verbose_name="所属网点")

class UserCoupon(models.Model):
    '''用户优惠券'''
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    coupon = models.ForeignKey(Coupon, on_delete=models.SET_NULL,blank=True,null=True, verbose_name="优惠券")
    status = models.BooleanField(default=True, verbose_name="优惠券状态")
    gettime = models.DateTimeField(verbose_name="获取时间", auto_now_add=True)
    class Mate:
        db_table = "usercoupon"


class Orderfg(models.Model):
    '''订单'''
    ordernum = models.CharField(max_length=64, verbose_name="订单编号")
    status = models.CharField(max_length=20, verbose_name="订单状态")
    sponsor = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="发起人")
    request_service = models.CharField(max_length=20, verbose_name="请求服务")
    equip= models.ForeignKey(Equipment, on_delete=models.CASCADE, verbose_name="设备")
    outlet= models.ForeignKey(Outlet, on_delete=models.CASCADE, verbose_name="网点",default=1)
    usedcoupon = models.ForeignKey(UserCoupon, on_delete=models.CASCADE, verbose_name="使用优惠券",blank=True,null=True,)
    usedscore = models.IntegerField(default=0, verbose_name="使用积分")
    cope_with = models.IntegerField(default=0, verbose_name="应付")
    pay = models.IntegerField(default=0, verbose_name="实付")


class UserServiceSession(models.Model):
    '''客服会话'''
    sid = models.CharField(max_length=20, verbose_name="会话编号")
    service = models.CharField(max_length=20, verbose_name="客服", default='小竹')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="用户")
    content = models.CharField(max_length=1000, verbose_name="会话内容")
    sendtime = models.DateTimeField(verbose_name="发送时间")
